export function _renderRect(ctx: any, rectForm: any) {
  if (rectForm.cornerRadius == 0 || !rectForm.cornerRadius) {
    _renderBaseRect(ctx, rectForm)
  } else {
    _renderComplexRect(ctx, rectForm)
  }
}

export function _renderBaseRect(ctx: any, rectForm: any) {
  let x = -rectForm.width / 2,
    y = -rectForm.height / 2,
    w = rectForm.width,
    h = rectForm.height
  ctx.beginPath()
  ctx.rect(x, y, w, h)
  ctx.closePath()
}

export function _renderComplexRect(ctx: any, rectForm: any) {
  let x = -rectForm.width / 2,
    y = -rectForm.height / 2,
    w = rectForm.width,
    h = rectForm.height,
    ltr = rectForm.cornerRadius[0] || 0,
    rtr = rectForm.cornerRadius[1] || 0,
    rbr = rectForm.cornerRadius[2] || 0,
    lbr = rectForm.cornerRadius[3] || 0

  ctx.beginPath()
  ctx.moveTo(x, y + ltr)
  ltr && ctx.arcTo(x, y, x + ltr, y, ltr)
  ctx.lineTo(x + w - rtr, y)
  rtr && ctx.arcTo(x + w, y, x + w, y + rtr, rtr)
  ctx.lineTo(x + w, y + h - rbr)
  rbr && ctx.arcTo(x + w, y + h, x + w - rbr, y + h, rbr)
  ctx.lineTo(x + lbr, y + h)
  lbr && ctx.arcTo(x, y + h, x, y + h - lbr, lbr)
  ctx.closePath()
}
